package com.lxf.cn.app;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.lxf.cn.model.User;


/**
 * Created by liaoxuefeng on 2018/12/17.
 */
public class Token {

     public static String getToken(User user){
         String token = "";
         try{
            user.setUserId(1);
            user.setPassword("123456");
            token= JWT.create().withAudience(user.getUserId().toString())// 将 user id 保存到 token 里面
                    .sign(Algorithm.HMAC256(user.getPassword()));// 以 password 作为 token 的密钥

        }catch (Exception e){
             e.printStackTrace();
        }
         return token;
     }

}
